﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;

public partial class Customer : System.Web.UI.Page
{
    Faisal_MoversEntities entites = new Faisal_MoversEntities();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateGrid();
        }

    }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        Model.Travel travel = new Travel();
        travel.route_id = int.Parse(Request.QueryString[0]);
        travel.travelDepatureTime = DateTime.Parse(TextBox1.Text);
        travel.travelArrivalTime = DateTime.Parse(TextBox2.Text);
        travel.travelDate = DateTime.Parse(TextBox3.Text);
        travel.price = int.Parse(TextBox4.Text);
        entites.Travels.AddObject(travel);
        entites.SaveChanges();
        PopulateGrid();

        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";

    }
    public void PopulateGrid()
    {
        int id = int.Parse(Request.QueryString[0]);
        var Customers_FeedBack = entites.Travels.Where(x => x.route_id == id).ToList();
        GridView1.DataSource = Customers_FeedBack;
        GridView1.DataBind();
    }
}